<template>

  <div class="bg">
    <div>
    <el-form
        :rules="rules"
        ref="loginForm"
        v-loading="loading"
        :model="loginForm"
        class="loginContainer">
      <h3 class="logintitle">系统登录</h3>
      <el-form-item prop="username">
        <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="请输入用户名"/>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="loginForm.password" auto-complete="off" @keydown.enter.native="Login" show-password placeholder="请输入密码"/>
      </el-form-item>
  <!--    <el-checkbox class="rem" v-model="checked">记住密码</el-checkbox>-->
      <el-button type="primary" id="loginbutton" style="width:100%" @click="Login">登录</el-button>
    </el-form>
  </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      loginForm:{
        username:'admin',
        password:'123'
      },
      rules:{
        username:[{required:true,message:'请输入用户名',trigger:'blur'}],
        password:[{required:true,message:'请输入密码',trigger:'blur'}]
      },
      loading:false
    }
  },
  mounted() {

  },
  methods: {
    Login() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading=true;
          this.postKeyValueRequest('/doLogin', this.loginForm).then(resp => {
            this.loading=false;
            if (resp) {
              window.sessionStorage.setItem("user",JSON.stringify(resp.obj));
              this.$store.commit('INIT_CURRENTHR',resp.obj);
              let path = this.$route.query.redirect;
              console.log(path);
              this.$router.replace((path=="/"||path==undefined)?"/home":path);
            }
          })
        } else {
          this.$message.error('用户名或密码未输入');
          return false;
        }
      });
    }
  }
}
</script>

<style>

.loginContainer{
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 0px 15px 15px 15px;
  background: #ffffff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
.logintitle{
  margin: 20px auto 15px auto;
  text-align: center;
  color:#303133;
}
.rem{
  text-align: left;
  margin: 0px 0px 10px 0px;
}
body{
  font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
}

el-button{
  text-align: center;
  margin: auto 25% auto 25%;
}


</style>